package com.sx.medicinecard.controller;


import com.alipay.api.AlipayApiException;
import com.aliyun.openservices.log.exception.LogException;
import com.google.protobuf.ServiceException;
import com.sx.medicinecard.common.ResponseResult;
import com.sx.medicinecard.common.ValidationGroups;
import com.sx.medicinecard.entity.SxSignContractBrush;
import com.sx.medicinecard.entity.dto.SxSignContractBrushDto;
import com.sx.medicinecard.entity.dto.SxSignContractDto;
import com.sx.medicinecard.service.SxSignContractBrushService;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.GroupSequence;
import javax.validation.Valid;
import javax.validation.groups.Default;
import java.io.UnsupportedEncodingException;

/**
 * 刷单签约表(SxSignContractBrush)控制层
 *
 * @author makejava
 * @since 2024-07-17 18:31:19
 */
@RestController
@RequestMapping("/sxSignContractBrush")
@Validated
public class SxSignContractBrushController {
    /**
     * 服务对象
     */
    @Resource
    private SxSignContractBrushService sxSignContractBrushService;

    @GroupSequence({ValidationGroups.NotBlankGroup.class, ValidationGroups.PatternGroup.class, Default.class})
    public interface ValidationSequence {}

    /**
     * 生成签约并支付链接(刷单)
     * @param sxSignContractBrushDto
     * @return
     */
    @PostMapping("/signAndPay")
    @ApiOperation("生成签约并支付链接(刷单)")
    public ResponseResult signAndPay(@RequestBody @Valid SxSignContractBrushDto sxSignContractBrushDto, HttpServletRequest request) throws AlipayApiException, UnsupportedEncodingException, ServiceException{
        return sxSignContractBrushService.signAndPay(sxSignContractBrushDto,request);
    }

    /**
     * 生成荷叶签约并支付链接(刷单)
     * @param sxSignContractBrushDto
     * @return
     */
    @PostMapping("/signAndPayHy")
    @ApiOperation("生成荷叶签约并支付链接(刷单)")
    public ResponseResult signAndPayHy(@RequestBody @Valid SxSignContractBrushDto sxSignContractBrushDto, HttpServletRequest request) throws ServiceException{
        return sxSignContractBrushService.signAndPayHy(sxSignContractBrushDto,request);
    }


    /**
     * 根据签约id获取签约链接（刷单）
     * @param signId
     * @return
     */
    @GetMapping("/getSignUrlById")
    @ApiOperation("根据签约id获取签约链接(刷单)")
    public ResponseResult getSignUrlById(@RequestParam("signId") String signId){
        return sxSignContractBrushService.getSignUrlById(signId);
    }



}

